<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link href="__INDEX__/css/Phoebe.css" rel="stylesheet" />
		<link href="__INDEX__/css/all.css" rel="stylesheet" />
		<link href="__INDEX__/css/stock.css" rel="stylesheet" />
		<link href="__PUBLIC__/static/css/agent_css.css" rel="stylesheet" />
		<title>进货</title>
	</head>
	<style>
		.my_shengou {
			float: left;
			width: 23%;
			height: 40px;
			line-height: 40px;
			font-size: 14px;
		}
		
		.buy_cls{
		    border: 1px solid #38d444;
		    padding: 5px;
		    background-color: #ee6565;
		    border-radius: 5px;
		    color: #fff;
		}
		.sell_cls{
		        border: 1px solid #38d444;
			    padding: 5px;
			    background-color: #7fdc82;
			    border-radius: 5px;
			    color: #fff;
		}
	</style>

	<body style="margin-top: 45px;">
		<header class="mui-bar mui-bar-nav">
			<a href="javascript:history.back(-1)" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">交易市场</h1>
			<a href="{:url('member/help_show3')}">规则</a>
		</header>
		<form >
		<!--进货-->
		<div class="stock">
			<div class="layui-form-item">
				<span class="my_shengou">产品名称 :</span>
				<div style="width: 65%;float: left;height: 40px;line-height: 40px;font-size: 14px; border: 1px solid #d4cece;border-radius: 4px;">
					<select id='goods_id' lay-filter="aihao">
						{volist name="goods_list" id="vo"}
							{if $vo.id == $goods_id}
								<option value="{$vo.id}">{$vo.name}</option>
							{else}
								<option value="">请选择产品</option>
							{/if}
						{/volist}
						{volist name="goods_list" id="vo"}
							{if $vo.id != $goods_id}
								<option value="{$vo.id}">{$vo.name}</option>
							{/if}
						{/volist}
					</select>
				</div>
			</div>
		</div>
		<div class="mui-scroll">
			<div style="width: 99%;margin-left: 2px;">
				<table class="zizh_table1">
					<thead>
						<tr style="text-align:center; background-color: #dad5d5;line-height: 39px;font-size: 16px;font-weight: bold;padding-left:0">
							<th>用户需求</th>
							<th>交易价格</th>
							<th>交易数量</th>
							<th>发起交易时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="tbody" style="text-align: center;">
						{volist name="order_list" id="vo"}
						<tr>
							<td>{if $vo.type == 1} 买入 {else} 卖出 {/if}
							</td>
							<td>{$vo.price}</td>
							<td>{$vo.num}</td>
							<td>{$vo.add_time}</td>
							<td>
								{if $vo.type == 1} 
									<button class="sell_cls" type="button" onclick="sellgd('{$vo.id}')">&nbsp; 卖出 &nbsp;</button>
								{else}
									<button class="buy_cls" type="button" onclick="buy('{$vo.id}')">&nbsp; 买入 &nbsp;</button>
								{/if}
							</td>
						</tr>
						{/volist}
					</tbody>
				</table>
				<div class="fenye" style="display: block;">
					{$order_list->appends(['goods_id'=>$goods_id])->render()}
				</div>
			</div>
		</div>
	</form>
	</body>

</html>
{include file="public/footer" /}
<!--<script type="text/javascript" src="js/stock.js"></script>-->
<script>
	$('#goods_id').change(function(){
		var goods_id = $("#goods_id").val();
		location.href = "../index/stock?goods_id="+goods_id;
	});
</script>
<script>
	function buy(order_id) {
		layui.config({
			base: '/public/static/js/'
		}).use('admin');
		var user_id = '{$Think.session.uid}';
	
		if(user_id == "" || user_id == null) {
			layer.msg("请先登录", {
				icon: 1,
				time: 1000 //2秒关闭（如果不配置，默认是3秒）
			}, function() {
				location.href = "{:url('index/login')}";
			});
			return 
		}
		var con = layer.confirm('确认操作?', function(index) {
			$.ajax({
				url: "{:url('index/buy_order')}",
				//请求的过程中传递过去的参数 json
				data: {
					order_id: order_id
				},
				//成功了的回调，并且带有返回值
				success: function(data) {
					layer.msg(data.msg, {
						icon: 1,
						time: 1000 //2秒关闭（如果不配置，默认是3秒）
					}, function() {
						if(data.code == 200) {
							location.href = "{:url('member/my_stock')}";
						}
					});
				}
			})
		});
	}
	
	function sellgd(order_id) {
		layui.config({
			base: '/public/static/js/'
		}).use('admin');
		var user_id = '{$Think.session.uid}';
	
		if(user_id == "" || user_id == null) {
			layer.msg("请先登录", {
				icon: 1,
				time: 1000 //2秒关闭（如果不配置，默认是3秒）
			}, function() {
				location.href = "{:url('index/login')}";
			});
			
			return
		}
		
		
		var con = layer.confirm('确认操作?', function(index) {
			$.ajax({
				url: "{:url('index/sell_order')}",
				//请求的过程中传递过去的参数 json
				data: {
					order_id: order_id
				},
				//成功了的回调，并且带有返回值
				success: function(data) {
					layer.msg(data.msg, {
						icon: 1,
						time: 1000 //2秒关闭（如果不配置，默认是3秒）
					}, function() {
						if(data.code == 200) {
							location.href = "{:url('member/my_market')}";
						}
					});
				}
			})
		});
	}
</script>